/**
 * 自定义接口
 * */


//关于我们
function getAboutList(){
    $.ajax({
        type: apis.about.method,
        url: apis.about.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key;
            for (var i = 0; i < d.length; i ++) {
                key = d[i].fkey;
                if (d[i].ftype == 3) {
                    $('#' + key).attr('src', d[i].fval);
                } else if (d[i].ftype == 4) {
                    part4List({k: key, v: d[i].fval});
                } else {
                    $('#' + key).html(d[i].fval);
                }
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//数据4列表
function part4List(e){
    var d = e.v, key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<div class="col-xl-4 col-md-6 col-lg-4">';
        h += '<div class="single_team" data-animation="fade-left" data-delay=".5">';
        h += '<a href="#" class="single_team_img cursor-arrow">';
        h += '<img src="' + d[i][0] + '" alt="team" class="img-fluid w-100"/>';
        h += '</a>';
        h += '<h3>' + d[i][1] + '</h3>';
        h += '<p>' + d[i][2] + '</p>';
        h += '</div>';
        h += '</div>';
    }
    $('#' + key).html(h);
}


//团队
function getTeamList(){
    $.ajax({
        type: apis.teamList.method,
        url: apis.teamList.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key;
            for (var i = 0; i < d.length; i ++) {
                key = d[i].fkey;
                if (d[i].ftype == 3) {
                    $('#' + key).attr('src', d[i].fval);
                } else if (d[i].ftype == 4) {
                    teamPart({k: key, v: d[i].fval});
                } else {
                    $('#' + key).html(d[i].fval);
                }
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//团队部分
function teamPart(e){
    var d = e.v, key = e.k;
    var h = '', i;
    for (i = 0; i < d.length; i ++) {
        h += '<div class="col-xl-4 col-md-6 col-lg-4">';
        h += '<div class="single_team" data-animation="fade-left">';
        h += '<a href="#" class="single_team_img cursor-arrow">';
        //h += '<img src="images/team_1.jpg" alt="team" class="img-fluid w-100"/>';
        h += '<img src="' + d[i][0] + '" alt="team" class="img-fluid w-100"/>';
        h += '</a>';
        h += '<h3>' + d[i][1] + '</h3>';
        h += '<p>' + d[i][2] + '</p>';
        h += '</div>';
        h += '</div>';
    }
    $('#' + key).html(h);
}


//联系我们
function getContact(){
    $.ajax({
        type: apis.contact.method,
        url: apis.contact.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                return
            }
            var d = res.data, key;
            for (var i = 0; i < d.length; i ++) {
                key = d[i].fkey;
                $('#' + key).html(d[i].fval);
            }
        },
        error: function () {
            console.log('错误辣');
        }
    });
}


//添加用户
function addUser(){
    var formData = {
        nick: $('#nick').val(),
        phone: $('#phone').val(),
        email: $('#email').val(),
        subject: $('#subject').val(),
        message: $('#message').val(),
    };
    console.log(formData);
    //return
    if (formData.nick == '') {
        alert('用户名必须的');
        return
    }
    if (formData.phone.length < 11) {
        alert('手机号必须的');
        return
    }
    $.ajax({
        type: apis.foot.method,
        url: apis.foot.url,
        data: {},
        success: function (res) {
            console.log(res);
            if (res.code < 0) {
                alert(res.msg);
                return
            }
            alert('添加成功');
            top.location.reload();
        },
        error: function () {
            console.log('错误辣');
        }
    });
}